home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual Foxpro 6.0 (Ent. Edition) / Vf6ent Extractor.EXE / API / SAMPLES / EVENT.C next >
Encoding:
C/C++ Source or Header  |  1998-05-26  |  9.6 KB  |  370 lines

  1. /*
  2. **
  3. *
  4. * EVENT.C - Sample API routine.
  5. *
  6. * Copyright (c) 1989-1993 Microsoft Corporation as an unpublished
  7. * licensed proprietary work.  All rights reserved.
  8. *
  9. * Description:
  10. *       This library will create an Event Handler which demonstrates when
  11. *       events are generated within FoxPro.  All events are processed, but
  12. *       do get passed on so FoxPro can handle them also.  When a null event
  13. *       is received, a counter is accumulated and once a different event has
  14. *       been received a total of the count is displayed.
  15. *
  16. *       This library creates a file called EVENT.TXT which captures the events
  17. *       and outputs the EventRec for each (except null events).  This file is
  18. *       currently created by using the _Execute() command to SET PRINT TO.  So,
  19. *       if you do anything while in FoxPro which uses the SET PRINT TO command,
  20. *       EVENT.TXT will not capture everything.  NOTE: not all of the information
  21. *       output through this routine for each event is relevant to that event.
  22. *
  23. **
  24. */
  25. #include <pro_ext.h>
  26.  
  27.  
  28. #define nl      _PutChr(0x0a);
  29.  
  30.  
  31. int         eventid;            // Our event handler
  32. long        num_nulls=0;        // accumulator of null events
  33.  
  34.  
  35.  
  36. /*      This routine will take a long integer and put it
  37.         into a Value structure which it then prints out.                */
  38.  
  39. PutInt(unsigned long number)
  40. {
  41.     Value       val;
  42.  
  43.  
  44.     val.ev_type = 'I';
  45.     val.ev_width = 10;
  46.     val.ev_long = number;
  47.     _PutValue(&val);
  48.  
  49.  
  50. }
  51.  
  52. /*      This routine checks to see if there were any null events
  53.         processed since the last time we had an event.   If there were,
  54.         then it prints out the number of null events that were processed
  55.         and resets the counter to 0.                                    */
  56.  
  57. ChkNulls()
  58. {
  59.  
  60.     if (num_nulls)              // if there were null events processed
  61.     {
  62.         _PutStr("\n\nNumber of Null Events Processed -> ");
  63.         PutInt(num_nulls);
  64.         num_nulls = 0;
  65.     }
  66.  
  67. }
  68.  
  69. /*      This routine takes a pointer to a WHandle and a point on the screen
  70.         as a parameter. It takes these parameters and determines in what
  71.         area of the window the point is.  It then prints out which area of
  72.         the window the mouse was pressed down in.                       */
  73.  
  74.  
  75. PrintFindWindow(WHandle FAR *window, Point win_point)
  76. {
  77.     int where;
  78.  
  79.  
  80.         where = _FindWindow(window, win_point);
  81.         _PutStr("In Window -> ");
  82.         switch (where)
  83.         {
  84.             case inBorder:
  85.                _PutStr("inBorder\n");
  86.                break;
  87.             case inHelp:
  88.                _PutStr("inHelp\n");
  89.                break;
  90.             case inContent:
  91.                _PutStr("inContent\n");
  92.                break;
  93.             case inDrag:
  94.                _PutStr("inDrag\n");
  95.                break;
  96.             case inGrow:
  97.                _PutStr("inGrow\n");
  98.                break;
  99.             case inGoAway:
  100.                _PutStr("inGoAway\n");
  101.                break;
  102.             case inZoom:
  103.                _PutStr("inZoom\n");
  104.                break;
  105.             case inVUpArrow:
  106.                _PutStr("inVUpArrow\n");
  107.                break;
  108.             case inVDownArrow:
  109.                _PutStr("invDownArrow\n");
  110.                break;
  111.             case inVPageUp:
  112.                _PutStr("inVPageUp\n");
  113.                break;
  114.             case inVPageDown:
  115.                _PutStr("inVPageDown\n");
  116.                break;
  117.             case inVThumb:
  118.                _PutStr("inVThumb\n");
  119.                break;
  120.             case inHUpArrow:
  121.                _PutStr("inHUpArrow\n");
  122.                break;
  123.             case inHDownArrow:
  124.                _PutStr("inHDownArrow\n");
  125.                break;
  126.             case inHPageUp:
  127.                _PutStr("inHPageUp\n");
  128.                break;
  129.             case inHPageDown:
  130.                _PutStr("inHPageDown\n");
  131.                break;
  132.             case inHThumb:
  133.                _PutStr("inHThumb\n");
  134.                break;
  135.             case inMenuBar:
  136.                _PutStr("inMenuBar\n");
  137.                break;
  138.         }
  139.  
  140. }
  141.  
  142.  
  143. /*      This procedure will check the which Modifiers were pressed when
  144.         a keyDownEvent was received.  It then will print out the
  145.         combination of the modifiers.                                   */
  146.  
  147. ChkModifiers(short modifiers)
  148. {
  149.  
  150.     int         others=FALSE;
  151.  
  152.         if (modifiers & altKey)         /* The Alt Key was pressed */
  153.         {
  154.                 if (modifiers & ctrlKey)     /* The Ctrl Key */
  155.                 {
  156.                     _PutStr("Ctrl");
  157.                     others = TRUE;
  158.                 }
  159.  
  160.                 if (modifiers & shiftKey)      /* The Shift Key */
  161.                 {
  162.                     if (others)
  163.                         _PutChr('+');
  164.                     _PutStr("Shift");
  165.                     others = TRUE;
  166.                 }
  167.  
  168.  
  169.                 if (others)
  170.                     _PutChr('+');
  171.                 _PutStr("Alt");
  172.  
  173.  
  174.         }
  175.         else
  176.         {
  177.             if (modifiers & ctrlKey)         /* Ctrl w/o Alt */
  178.                 if (modifiers & shiftKey)     /* check for Shift */
  179.                     _PutStr("Ctrl+Shift");
  180.                 else
  181.                     _PutStr("Ctrl");
  182.             else
  183.                 if (modifiers & shiftKey)     /* Shift w/o Alt and Ctrl */
  184.                     _PutStr("Shift");
  185.         }
  186.  
  187.  
  188.         _PutChr(0x0a);
  189.         others = FALSE;
  190.  
  191.  
  192. }
  193.  
  194. // Print the Event record's objects to the current output port.
  195.  
  196. PrintEvent(EventRec FAR *ev, char FAR *whatevent)
  197. {
  198.  
  199.  
  200. /*  The following is the definition for the Event Record which is
  201.     defined in pro_ext.h.
  202.  
  203.  
  204.         Event record definitions
  205.         typedef struct
  206.         {
  207.         unsigned short      what;            Event code
  208.         Ticks               when;            Ticks since startup
  209.         Point               where;           Mouse location
  210.         unsigned long       message;         Key/window
  211.         unsigned long       misc;            Event dependant misc info
  212.         unsigned long       misc2;           Event dependant misc info
  213.         unsigned char       mbState;         Mouse buttons state
  214.         unsigned char       mcState;         Mouse cond activate state
  215.         unsigned short      modifiers;
  216.         } EventRec;
  217.  
  218. */
  219.  
  220.  
  221.     ChkNulls();                 // Check for null events
  222.     _PutStr("\n\n*******  New Event ********\n\n");
  223.  
  224.     _PutStr("What Event -> ");
  225.     _PutStr(whatevent); nl;
  226.  
  227.     _PutStr("Horizontal mouse location -> ");
  228.     PutInt((long) ev->where.h); nl;
  229.  
  230.     _PutStr("Vertical mouse location -> ");
  231.     PutInt((long) ev->where.v); nl;
  232.  
  233.     _PutStr("Event message -> ");
  234.                                         // check if a regular key was pressed
  235.     if (ev->what == keyDownEvent && !(ev->modifiers & shiftCodeMask))
  236.        _PutChr((char) ev->message);
  237.     else
  238.         PutInt(ev->message); nl;
  239.  
  240.     _PutStr("Event misc info -> ");
  241.     PutInt(ev->misc); nl;
  242.  
  243.     _PutStr("Event misc2 info -> ");
  244.     PutInt(ev->misc2); nl;
  245.  
  246.     if (ev->mbState == leftButton)
  247.         _PutStr("Mouse button state ->  Left mouse button\n");
  248.  
  249.  
  250.     _PutStr("Event modifiers -> ");
  251.     ChkModifiers(ev->modifiers);
  252.  
  253.  
  254. }
  255.  
  256.  
  257. //
  258. // This routine is registered as an event handler.
  259. //
  260.  
  261. FAR EventHandler(WHandle theWindow, EventRec FAR *ev)
  262. {
  263.  
  264.  
  265.  
  266.     switch(ev->what)
  267.     {
  268.     case nullEvent:
  269.            num_nulls++;
  270.            return NO;
  271.  
  272.     case mouseDownEvent:
  273.            PrintEvent(ev, "mouseDownEvent");
  274.            PrintFindWindow(&theWindow, ev->where);
  275.            return NO;
  276.            break;
  277.  
  278.     case keyDownEvent:
  279.            PrintEvent(ev, "keyDownEvent");
  280.            return NO;
  281.            break;
  282.  
  283.         case activateEvent:
  284.            PrintEvent(ev, "activateEvent");
  285.            return NO;
  286.            break;
  287.  
  288.         case deactivateEvent:
  289.            PrintEvent(ev, "deactivateEvent");
  290.            return NO;
  291.            break;
  292.  
  293.         case menuHitEvent:
  294.            PrintEvent(ev, "menuHitEvent");
  295.            return NO;
  296.            break;
  297.  
  298.         case closeEvent:
  299.            PrintEvent(ev, "closeEvent");
  300.            return NO;
  301.            break;
  302.  
  303.         case hideEvent:
  304.            PrintEvent(ev, "hideEvent");
  305.            return NO;
  306.            break;
  307.  
  308.         case showEvent:
  309.            PrintEvent(ev, "showEvent");
  310.            return NO;
  311.            break;
  312.  
  313.         case hotkeyEvent:
  314.            PrintEvent(ev, "hotkeyEvent");
  315.            return NO;
  316.            break;
  317.  
  318.         case sizeEvent:
  319.            PrintEvent(ev, "sizeEvent");
  320.            return NO;
  321.            break;
  322.  
  323.         case zoomEvent:
  324.            PrintEvent(ev, "zoomEvent");
  325.            return NO;
  326.            break;
  327.  
  328.  
  329.     default:
  330.         return NO;
  331.     }
  332.     return YES;
  333. }
  334.  
  335.  
  336. /*      This is our procedure which sets up the event handler and creates
  337.         the text file to capture all of the events.                     */
  338.  
  339. FAR Event()
  340. {
  341.  
  342.     eventid = _ActivateHandler(EventHandler);
  343.     _Execute("SET PRINT TO EVENT.TXT");
  344.     _Execute("SET PRINT ON");
  345.  
  346. }
  347.  
  348.  
  349.  
  350. /*      When we unload the library, we cleanup our mess!  First deactivating
  351.         the event handler and then closing our text file.               */
  352.  
  353. FAR EventExit()
  354. {
  355.  
  356.     _DeActivateHandler(eventid);
  357.     _Execute("SET PRINT OFF");
  358.     _Execute("SET PRINT TO");
  359.  
  360. }
  361.  
  362. FoxInfo myFoxInfo[] = {
  363.     {"EVENT", (FPFI) Event, CALLONLOAD, ""},
  364.     {"EVENTEXIT", (FPFI) EventExit, CALLONUNLOAD, ""}
  365. };
  366.  
  367. FoxTable _FoxTable = {
  368.     (FoxTable FAR *)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo
  369. };
  370.